package com.yztc.orangeentertainment.ui.main.findfragment.findui;

import android.content.Context;

import com.yztc.orangeentertainment.bean.findbean.FindChangeBean;
import com.yztc.orangeentertainment.bean.findbean.FindChangeDataBean;
import com.yztc.orangeentertainment.bean.findbean.FindHotBean;
import com.yztc.orangeentertainment.bean.findbean.FindHotDataListBean;
import com.yztc.orangeentertainment.bean.findbean.FindMoreBean;
import com.yztc.orangeentertainment.bean.findbean.FindMoreDataBean;
import com.yztc.orangeentertainment.config.SubscribeUrlConfig;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import rx.Subscriber;

/**
 * Created by My on 2016/10/13.
 */
public class FindPresenter implements FindContract.Presenter {
    private FindContract.Modle modle;
    private FindContract.Modle changeModle;
    private FindContract.Modle hotModle;
    private FindContract.View view;
    private FindContract.FindChangeView findChangeView;
    private FindContract.FindHotView hotview;

    public FindPresenter(FindContract.View view) {
        this.view = view;
        this.modle = new FindModle();
    }

    public FindPresenter(FindContract.FindChangeView findChangeView) {
        this.findChangeView = findChangeView;
        this.changeModle = new FindModle();
    }

    public FindPresenter(FindContract.FindHotView hotView) {
        this.hotview = hotView;
        this.hotModle = new FindModle();
    }

    @Override
    public void getFindMoreDataBeanFromNet(String url, Context context) {
        modle.getFindMoreDataBean(url, context, new Subscriber<FindMoreBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                view.getFindMoreDataBeanFail("" + e.getMessage());
            }

            @Override
            public void onNext(FindMoreBean findMoreBean) {
                FindMoreDataBean findMoreDataBean = findMoreBean.getData();
                view.getFindMoreDataBeanSucess(findMoreDataBean);
            }
        });
    }

    @Override
    public void getFindChangeBeanFromNet(int page) {
        Map<String, String> map = new HashMap<>();
        map.put("page", String.valueOf(page));
        map.put(SubscribeUrlConfig.Params.MAC, SubscribeUrlConfig.All_DefaultVaule.MAC_VALUE);
        map.put(SubscribeUrlConfig.Params.UID, SubscribeUrlConfig.All_DefaultVaule.UID_VALUE);
        map.put(SubscribeUrlConfig.Params.PF, SubscribeUrlConfig.All_DefaultVaule.PF_VALUE);
        map.put(SubscribeUrlConfig.Params.NET, SubscribeUrlConfig.All_DefaultVaule.NET_VALUE);
        map.put(SubscribeUrlConfig.Params.ACCESSTOKEN, SubscribeUrlConfig.All_DefaultVaule
                .ACCESSTOKEN_VALUE);
        map.put(SubscribeUrlConfig.Params.CHANNEL, SubscribeUrlConfig.All_DefaultVaule
                .CHANNEL_VALUE);
        map.put(SubscribeUrlConfig.Params.VER, SubscribeUrlConfig.All_DefaultVaule.VER_VALUE);
        map.put(SubscribeUrlConfig.Params.RES, SubscribeUrlConfig.All_DefaultVaule.RES_VALUE);
        changeModle.getFindChangeBean("wewatch", map, new Subscriber<FindChangeBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                findChangeView.getFindChangeDataBeanFail(e.getMessage());
            }

            @Override
            public void onNext(FindChangeBean findChangeBean) {
                List<FindChangeDataBean> changeDataBeens = findChangeBean.getData();
                findChangeView.getFindChangeDataBeanSucess(changeDataBeens);
            }
        });
    }

    @Override
    public void getFindHotDataListBeanFromNet() {
        Map<String, String> map = new HashMap<>();
        map.put("page", "1");
        map.put("ts", "0");
        map.put(SubscribeUrlConfig.Params.MAC, SubscribeUrlConfig.All_DefaultVaule.MAC_VALUE);
        map.put(SubscribeUrlConfig.Params.UID, SubscribeUrlConfig.All_DefaultVaule.UID_VALUE);
        map.put(SubscribeUrlConfig.Params.PF, SubscribeUrlConfig.All_DefaultVaule.PF_VALUE);
        map.put(SubscribeUrlConfig.Params.NET, SubscribeUrlConfig.All_DefaultVaule.NET_VALUE);
        map.put(SubscribeUrlConfig.Params.ACCESSTOKEN, SubscribeUrlConfig.All_DefaultVaule
                .ACCESSTOKEN_VALUE);
        map.put(SubscribeUrlConfig.Params.CHANNEL, SubscribeUrlConfig.All_DefaultVaule
                .CHANNEL_VALUE);
        map.put(SubscribeUrlConfig.Params.VER, SubscribeUrlConfig.All_DefaultVaule.VER_VALUE);
        map.put(SubscribeUrlConfig.Params.RES, SubscribeUrlConfig.All_DefaultVaule.RES_VALUE);

        hotModle.getFindHotDataListBean("hotnotice", map, new Subscriber<FindHotBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                hotview.getFindHotDataListBeanFail(e.getMessage());
            }

            @Override
            public void onNext(FindHotBean findHotBean) {
                List<FindHotDataListBean> hotDataListBeens = findHotBean.getData().getList();
                hotview.getFindHotDataListBeanSucess(hotDataListBeens);
            }
        });
    }
}
